<template>
    <div class="container">
        <h1>注册</h1>
        <input placeholder="用户名" v-model="username"/>
        <input placeholder="手机账号" v-model="phone"/>
        <input placeholder="年龄" type="number" v-model="age"/>
        <input placeholder="密码" type="password" v-model="pwd"/>
        <input placeholder="邮箱" v-model="email"/>
        <button @click="register">注册</button>
        <router-link to="/login"  class="router-link">返回登录</router-link>
    </div>
</template>

<script>
import axios from 'axios';
import '../../assets/style.css'

export default {
    data() {
        return {
            username: '',
            phone: '',
            pwd: '',
            age: null,
            email: ''
        }
    },
    methods: {
        register() {
            axios.post('http://localhost:8080/shopping/login/register', {
                userName: this.username,
                phone: this.phone,
                pwd: this.pwd,
                age: this.age,
                email: this.email
            }).then(response => {
                if (response.data.code === 200) {
                    this.$router.push('/login')
                } else {
                    this.$message.error(response.data.msg)
                }
            }).catch(error => {
                this.$message.error(error)
            });
        }
    }
}
</script>